package com.situ.mall.thrad;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadDemo {

    public static void main3(String[] args) {
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable, "Runnable线程");
        thread.start();
    }

    public static void main2(String[] args) {
        MyThread myThread = new MyThread("我的线程");
        //这不是启动一个线程，这是调用对象里面一个普通的方法run
        //myThread.run();
        //真正启动线程调用start方法，执行代码就是run方法里面代码
        myThread.start();
    }

    public static void main4(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("ThreadDemo.run");
            }
        });
        thread.start();

        new Thread(new Runnable() {
            @Override
            public void run() {

            }
        }).start();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        FutureTask<String> futureTask = new FutureTask<>(myCallable);
        Thread thread = new Thread(futureTask, "CallableThread");
        thread.start();
        String result = futureTask.get();
        System.out.println(result);
    }
}
